package com.yimulin.mobile.ui.activity

import android.animation.Animator
import android.app.Application
import android.app.Dialog
import android.content.Intent
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import com.airbnb.lottie.LottieAnimationView
import com.blankj.utilcode.util.SpanUtils
//import com.bytedance.applog.AppLog
//import com.bytedance.applog.InitConfig
//import com.bytedance.applog.util.UriConstants
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar
import com.hjq.http.EasyConfig
import com.hjq.widget.view.SlantedTextView
import com.pdlbox.tools.utils.SpUtils
import com.yimulin.mobile.R
import com.yimulin.mobile.app.AppActivity
import com.yimulin.mobile.manager.ActivityManager
import com.yimulin.mobile.manager.UserManager
import com.yimulin.mobile.other.AppConfig
import java.util.Locale


/**
 *    author : Android 轮子哥
 *    github : https://github.com/getActivity/AndroidProject-Kotlin
 *    time   : 2018/10/18
 *    desc   : 闪屏界面
 */
class SplashActivity : AppActivity() {

    private val lottieView: LottieAnimationView? by lazy { findViewById(R.id.lav_splash_lottie) }
    private val debugView: SlantedTextView? by lazy { findViewById(R.id.iv_splash_debug) }
//    private val mSplashContainer: FrameLayout? by lazy { findViewById(R.id.ad_view) }

//    //@[classname]
//    private var csjSplashAdListener: CSJSplashAdListener? = null
//
//    //@[classname]
//    private var splashAdListener: CSJSplashAd.SplashAdListener? = null
//
//    //@[classname]
//    private var csjSplashAd: CSJSplashAd? = null

    override fun getLayoutId(): Int {
        return R.layout.splash_activity
    }

    override fun initView() {

        UserManager.init()

        postDelayed({
            startActivity(MainActivity::class.java)
//                HomeActivity.start(this@SplashActivity)
            finish()
        }, 5000)

        // 设置动画监听
        lottieView?.addAnimatorListener(object : Animator.AnimatorListener {
            override fun onAnimationStart(p0: Animator) {

            }

            override fun onAnimationEnd(animation: Animator) {
                lottieView?.removeAnimatorListener(this)
                startActivity(MainActivity::class.java)
//                HomeActivity.start(this@SplashActivity)
                finish()
            }

            override fun onAnimationCancel(p0: Animator) {

            }

            override fun onAnimationRepeat(p0: Animator) {

            }
        })

        //判断是否同意隐私政策
//        if (!SpUtils.getBoolean("APP_CONFIG", "AGREE_AGREEMENT", false)) {
//            showYszcDialog()
//        } else {
//            checkLogin()
//        }
    }

    override fun initData() {
        debugView?.let {
            it.setText(AppConfig.getBuildType().uppercase(Locale.getDefault()))
            if (AppConfig.isDebug()) {
                it.visibility = View.VISIBLE
            } else {
                it.visibility = View.INVISIBLE
            }
        }

    }

    override fun createStatusBarConfig(): ImmersionBar {
        return super.createStatusBarConfig()
            // 隐藏状态栏和导航栏
            .hideBar(BarHide.FLAG_HIDE_BAR)
    }

    override fun onBackPressed() {
        // 禁用返回键
        //super.onBackPressed();
    }

    override fun initActivity() {
        // 问题及方案：https://www.cnblogs.com/net168/p/5722752.html
        // 如果当前 Activity 不是任务栈中的第一个 Activity
        if (!isTaskRoot) {
            val intent: Intent? = intent
            // 如果当前 Activity 是通过桌面图标启动进入的
            if (((intent != null) && intent.hasCategory(Intent.CATEGORY_LAUNCHER)
                        && (Intent.ACTION_MAIN == intent.action))
            ) {
                // 对当前 Activity 执行销毁操作，避免重复实例化入口
                finish()
                return
            }
        }
        super.initActivity()
    }

    /**
     * 展示隐私政策弹框
     */
    private fun showYszcDialog() {
        val dialog = Dialog(this, R.style.BottomDialog)
        val contentView = LayoutInflater.from(this).inflate(R.layout.dialog_yszc_layout, null)
        dialog.setContentView(contentView)
        dialog.setCanceledOnTouchOutside(false)
        dialog.setCancelable(false)
        val layoutParams = contentView.layoutParams
        layoutParams.width = resources.displayMetrics.widthPixels
        contentView.layoutParams = layoutParams
        dialog.window?.setWindowAnimations(R.style.BottomDialog_Animation)
        val tvTitle = contentView.findViewById<TextView>(R.id.title)
        val tvMessage = contentView.findViewById<TextView>(R.id.message)
        val negativeButton = contentView.findViewById<TextView>(R.id.negativeButton)
        val positiveButton = contentView.findViewById<TextView>(R.id.positiveButton)
        negativeButton.text = "拒绝并退出"
        positiveButton.text = "同意"
        tvTitle.text = "用户协议和隐私政策"
        SpanUtils.with(tvMessage)
            .append("亲爱的用户，本软件的正常使用需要依法征用您的登录身份个人信息，本平台承诺将严格保护您个人信息，确保信息安全，具体详见我方按照相关法律法规要求制定的")
            .append("《用户协议》")
            .setClickSpan(Color.parseColor("#43CF7C"), false) {
                BrowserActivity.start(this, AppConfig.getUserAgreement())
            }
            .append("及")
            .append("《隐私政策》")
            .setClickSpan(Color.parseColor("#43CF7C"), false) {
                BrowserActivity.start(this, AppConfig.getPrivacyPolicy())
            }.create()
        dialog.show()

        positiveButton.setOnClickListener {
            SpUtils.put("APP_CONFIG", "AGREE_AGREEMENT", true)
//            checkLogin()
//            startActivity(GuideActivity::class.java)
            dialog.dismiss()
        }
        negativeButton.setOnClickListener {
            dialog.dismiss()
            // 移动到上一个任务栈，避免侧滑引起的不良反应
            moveTaskToBack(false)
            postDelayed({
                // 进行内存优化，销毁掉所有的界面
                ActivityManager.getInstance().finishAllActivities()
            }, 300)
        }
    }

//    private fun checkLogin() {
////        initCsjApplog(application)
////        initCsjSdk(application)
//        // 友盟统计、登录、分享 SDK
//        val channel = AppConfig.getChannel()
//        UmengClient.init(application, AppConfig.isLogEnable(), channel)
//        CrashReport.initCrashReport(application, AppConfig.getBuglyId(), AppConfig.isDebug())
//
//        MapsInitializer.updatePrivacyShow(this, true, true)
//        MapsInitializer.updatePrivacyAgree(this, true)
//
//        postDelayed({
//            MainActivity.start(this@SplashActivity)
//            finish()
//        }, 3000)
//    }

    /**
     * 初始化穿山甲
     */
//    private fun initCsjSdk(application: Application?) {
//        val configJsonStr =
//            "{\"cypher\":2,\"message\":\"2IJ3ZlHYp39ycI3ik40ET1aJTLFGVHcIWS5/VRiWhndSK9MR5WXXcY4FgAGb/rd8ueyzFPyQSoJ/X9jO7TRgLXrOJZFUGObDBn2PG+p0etE1W08kG76JCgeae3X4ko8qfEB3rdQYkyo2cA4LtSZA4kknh6qs13PFrvwQY87gf0BFQH35jtGJOffWvw9Z1h3RDIXMOJ19nxyDiQNOY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r+TzO1dC206UwTnKqtWZbr9Iat2rCxoc7ZHQoUUh0F6V7NcY38wRG8L0KCnIjL0zkuMKofukzCJZqEEyc23eTj9YsNOacZC4aRKwoSmBk1HUzMDelPvROyiRNYUtw0NLStOYLGqC6ICb/8rGT5y3XEYwuYmPmaxt+QpvUtjvRHm328n/hkvUKyVOjsojVZXpMaWJGES1/hW7euv/CQwbI/rnKo6rIfYzU/LHJujI9aAw4ijWKHiozqFuPkETRGR3ZjH1IqElyQ5CeLxOWhgufuxei5cIdQgq38zKBYgTjLaTnJe169QVedxCP8Ajm7xjWXevevXH+5/3yv/jrE8rD54Gd/PQLmubWxUDlnDBqrRhSbMGOSZ8vMApIn3V2eR0YkWO/hzfgSWCiOY85RK6yRCvWNHW68Wgq2ppu5sxHr+WgiPHtXGx1eADxBCCWLPLVoc75TQluRW29ijDa6tJyWNQuw2rHFh7c6bGEVS2ch329/3U1AkbJwyGQbeQaiwehWsbCG0KPtn9tVKdami39RN+FawOmu8FkN\"}"
//        var configJsonObj: JSONObject? = null
//        try {
//            configJsonObj = JSONObject(configJsonStr)
//        } catch (e: JSONException) {
//            Logger.e("初始化穿山甲默认配置json失败")
//        }
//
//        val sdkVersion = TTAdSdk.getAdManager().getSDKVersion()
//        Logger.d("SDK_VERSION:${sdkVersion}")
//        TTAdSdk.init(
//            application, TTAdConfig.Builder()
//                .appId("5465945")
//                .useMediation(true)//开启聚合功能，默认false
//                .debug(AppConfig.isDebug())
//                .setMediationConfig(
//                    MediationConfig.Builder()
//                        .setCustomLocalConfig(configJsonObj)
//                        .build()
//                )
//                .customController(object : TTCustomController() {
//                    override fun alist(): Boolean {
//                        return false
//                    }
//
//                    override fun isCanUseWifiState(): Boolean {
//                        return false
//                    }
//
//                    override fun isCanUseLocation(): Boolean {
//                        return false
//                    }
//                })
//                .build()
//        )
//        TTAdSdk.start(object : TTAdSdk.Callback {
//            override fun success() {
//                Logger.d("CSJAD_success:" + TTAdSdk.isSdkReady())
//
//                //1. 初始化，最好放到application.onCreate()执行
//                val configBuilder = DPSdkConfig.Builder()
//                    .debug(AppConfig.isDebug())
//                DPSdk.init(
//                    AppApplication.getApplication(),
//                    DemoConst.SDK_SETTINGS_CONFIG,
//                    configBuilder.build()
//                )
//                DPSdk.start { isSuccess, message ->
//                    //请确保使用Sdk时Sdk已经成功启动
//                    //isSuccess=true表示启动成功
//                    //启动失败，可以再次调用启动接口（建议最多不要超过3次)
////                    isDPStarted = isSuccess
//                    Logger.e("短视频start result=$isSuccess, msg=$message")
////                    Bus.getInstance().sendEvent(DPStartEvent(isSuccess))
//                    loadAd()
//                }
//                val config = DJXSdkConfig.Builder().debug(AppConfig.isDebug()).build()
//                // 初始化，最好放到application.onCreate()执行
//                DJXSdk.init(AppApplication.getApplication(), DemoConst.SDK_SETTINGS_CONFIG, config)
//                //需要在广告SDK初始化成功后启动短剧服务
//                DJXSdk.start { isSuccess, message ->
//                    // ...
//                    Logger.e("短剧start result=$isSuccess, msg=$message")
//                }
//            }
//
//            override fun fail(p0: Int, p1: String?) {
//                Logger.d("CSJAD_fail:${p0}, ${p1}")
//                jumpActivity()
//            }
//        })
//    }

//    fun loadAd() {
//        val appScreenWidth = ScreenUtils.getScreenWidth()
//        val appScreenHeight = ScreenUtils.getScreenHeight()
//        Logger.d("屏幕宽高：${appScreenWidth}, ${appScreenHeight}")
//        /** 1、创建AdSlot对象 */
//        //@[classname]
//        val adslot = AdSlot.Builder()
//            .setCodeId("103025799")
//            .setImageAcceptedSize(
//                appScreenWidth,
//                appScreenHeight
//            )
//            .build()
//
//        /** 2、创建TTAdNative对象 */
//        //@[classname]//@[methodname]
//        val adNativeLoader = TTAdSdk.getAdManager().createAdNative(this@SplashActivity)
//
//        /** 3、创建加载、展示监听器 */
//        initListeners()
//
//        /** 4、加载广告  */
//        adNativeLoader.loadSplashAd(adslot, csjSplashAdListener, 3500)
//    }

    //@[classname]
//    fun showAd(csjSplashAd: CSJSplashAd?) {
//        /** 5、渲染成功后，展示广告 */
//        this.csjSplashAd = csjSplashAd
//        csjSplashAd?.setSplashAdListener(splashAdListener)
//        csjSplashAd?.let {
//            it.splashView?.let { splashView ->
//                mSplashContainer?.addView(splashView)
//            }
//        }
//    }

//    private fun initListeners() {
//        // 广告加载监听器
//        //@[classname]
//        csjSplashAdListener = object : CSJSplashAdListener {
//            //@[classname]
//            override fun onSplashLoadSuccess(ad: CSJSplashAd?) {
//                Logger.d("onSplashAdLoad")
//            }
//
//            //@[classname]
//            override fun onSplashLoadFail(error: CSJAdError?) {
//                Logger.d("onError code = ${error?.code} msg = ${error?.msg}")
//                jumpActivity()
//            }
//
//            //@[classname]
//            override fun onSplashRenderSuccess(ad: CSJSplashAd?) {
//                Logger.d("onSplashRenderSuccess")
//                showAd(ad)
//            }
//
//            //@[classname]
//            override fun onSplashRenderFail(ad: CSJSplashAd?, error: CSJAdError?) {
//                Logger.d("onError code = ${error?.code} msg = ${error?.msg}")
//                jumpActivity()
//            }
//        }
//        //@[classname]
//        splashAdListener = object : CSJSplashAd.SplashAdListener {
//            //@[classname]
//            override fun onSplashAdShow(p0: CSJSplashAd?) {
//                Logger.d("onSplashAdShow")
//            }
//
//            //@[classname]
//            override fun onSplashAdClick(p0: CSJSplashAd?) {
//                Logger.d("onSplashAdClick")
//            }
//
//            //@[classname]
//            override fun onSplashAdClose(p0: CSJSplashAd?, closeType: Int) {
//                //@[classname]
//                if (closeType == CSJSplashCloseType.CLICK_SKIP) {
//                    Logger.d("开屏广告点击跳过")
//                    //@[classname]
//                } else if (closeType == CSJSplashCloseType.COUNT_DOWN_OVER) {
//                    Logger.d("开屏广告点击倒计时结束")
//                    //@[classname]
//                } else if (closeType == CSJSplashCloseType.CLICK_JUMP) {
//                    Logger.d("点击跳转")
//                }
//                jumpActivity()
//            }
//        }
//    }

    private fun jumpActivity() {
        if (UserManager.tokenResult == null) {
            startActivity(LoginActivity::class.java)
        } else {
            // 更新 Token
            EasyConfig.getInstance()
                .addHeader("Authorization", "Bearer ${UserManager.tokenResult?.getToken()}")
            MainActivity.start(this@SplashActivity)
        }
        finish()
    }

//    /**
//     * 初始化穿山甲视频
//     */
//    private fun initCsjApplog(application: Application?) {
//
//        /* 初始化开始，appid和渠道，appid如不清楚请联系客户成功经理
//        * 注意第二个参数 channel 不能为空
//        */
//        val config = InitConfig("576882", AppConfig.getChannel())
//        //上报地址
//        config.setUriConfig(UriConstants.DEFAULT)
//        // 加密开关，SDK 5.5.1 及以上版本支持，false 为关闭加密，上线前建议设置为 true
//        AppLog.setEncryptAndCompress(true)
//
//        config.setAutoStart(true)
//        /* 初始化结束 */
//        config.setAutoStart(true)
//
//        AppLog.init(this, config)
//    }

//    override fun onDestroy() {
//        super.onDestroy()
//        /** 6、在onDestroy中销毁广告  */
//        csjSplashAd?.mediationManager?.destroy()
//    }
}